package com.oa.dao.impl;

import com.oa.dao.DeptDao;
import com.oa.pojo.Dept;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author wzm
 * @create 2023-11-13 10:09
 * project_name:web2310
 * @Description
 */
public class DeptDaoImpl extends BaseDao implements DeptDao {
    @Override
    public List<Dept> selectByAll() {
        return selectForList(Dept.class,"select id,dept_no deptNo,dept_name deptName,dept_location deptLocation, status from dept");
    }

    @Override
    public int insert(Dept dept) {
        return update(
                "insert into dept values(?,?,?,?,?,?,?,?,?)",
                dept.getId(),dept.getDeptNo(),
                dept.getDeptName(),
                dept.getDeptLocation(),
                dept.getStatus(),
                dept.getCreateUser(),
                dept.getCreateTime(),
                dept.getUpdateTime(),
                dept.getUpdateTime()
        );
    }

    @Override
    public Dept selectById(int id) {
        return selectbyOne(Dept.class,"select  id,dept_no deptNo,dept_name deptName,dept_location deptLocation, status from dept where id =?",id);
    }

    @Override
    public int update(Dept dept) {
        //对一些页面没有传入的值进行设定
        dept.setUpdateTime(LocalDateTime.now());//修改时间为当前时间

        return update("update dept set dept_no = ?,dept_name = ?,dept_location = ?,update_time = ? where id = ? "
                ,dept.getDeptNo(),dept.getDeptName(),dept.getDeptLocation(),dept.getUpdateTime(),dept.getId());
    }

    @Override
    public int delete(int id) {
        return update("delete from dept where id = ?", id);
    }
}
